package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.BedInfoVo;
import org.dromara.nursing.domain.bo.BedInfoBo;
import org.dromara.nursing.service.IBedInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 床位管理
 *
 * @author Xue
 * @date 2025-04-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/bedInfo")
public class BedInfoController extends BaseController {

    private final IBedInfoService bedInfoService;

    /**
     * 查询床位管理列表
     */
    @SaCheckPermission("nursing:bedInfo:list")
    @GetMapping("/list")
    public TableDataInfo<BedInfoVo> list(BedInfoBo bo, PageQuery pageQuery) {
        return bedInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出床位管理列表
     */
    @SaCheckPermission("nursing:bedInfo:export")
    @Log(title = "床位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BedInfoBo bo, HttpServletResponse response) {
        List<BedInfoVo> list = bedInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "床位管理", BedInfoVo.class, response);
    }

    /**
     * 获取床位管理详细信息
     *
     * @param bedId 主键
     */
    @SaCheckPermission("nursing:bedInfo:query")
    @GetMapping("/{bedId}")
    public R<BedInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long bedId) {
        return R.ok(bedInfoService.queryById(bedId));
    }

    /**
     * 新增床位管理
     */
    @SaCheckPermission("nursing:bedInfo:add")
    @Log(title = "床位管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BedInfoBo bo) {
        return toAjax(bedInfoService.insertByBo(bo));
    }

    /**
     * 修改床位管理
     */
    @SaCheckPermission("nursing:bedInfo:edit")
    @Log(title = "床位管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BedInfoBo bo) {
        return toAjax(bedInfoService.updateByBo(bo));
    }

    /**
     * 删除床位管理
     *
     * @param bedIds 主键串
     */
    @SaCheckPermission("nursing:bedInfo:remove")
    @Log(title = "床位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{bedIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] bedIds) {
        return toAjax(bedInfoService.deleteWithValidByIds(List.of(bedIds), true));
    }
}
